//
//  BVMineTool.m
//  XiangYu
//
//  Created by YYKJ on 2017/6/22.
//  Copyright © 2017年 YYKJ. All rights reserved.
//

#import "BVMineTool.h"
#import "BVMineModel.h"

#define CODE @"1"
@implementation BVMineTool

- (void)loginTel:(NSString *)tel
        password:(NSString *)password
         success:(void(^)(NSString *status))success
     codeFailure:(void(^)(NSString *status))codeFailure
         failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/index.php?s=/app/user/login.html",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"username"] = tel;
    params[@"password"] = password;
    
    [[BVHttpManager sharedNetManager]requstUrl:url method:Post parameters:params success:^(id responseObject) {
        BVLog(@"-------%@",responseObject);
        NSString *str= [NSString stringWithFormat:@"%@",responseObject[@"status"]];
        if (([str isEqualToString:CODE] && responseObject!=nil)) {
            [self.user setUser_id:responseObject[@"userinfo"][@"uid"]];
            success(responseObject[@"info"]);
        }else{
            codeFailure(responseObject[@"info"]);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

+ (void)reSetPwdMobile:(NSString *)mobile
                newPwd:(NSString *)newPwd
                  code:(NSString *)code
               success:(void(^)(NSString *status))success
           codeFailure:(void(^)(NSString *status))codeFailure
               failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/index.php?s=/app/user/doReset.html",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"mobile"] = mobile;
    params[@"code"] = code;
    params[@"password"] = newPwd;
    
    [[BVHttpManager sharedNetManager]requstUrl:url method:Post parameters:params success:^(id responseObject) {
        BVLog(@"-------%@",responseObject);
        NSString *str= [NSString stringWithFormat:@"%@",responseObject[@"status"]];
        if (([str isEqualToString:CODE] && responseObject!=nil)) {
            success(responseObject[@"message"]);
        }else{
            codeFailure(responseObject[@"message"]);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
    
}

+ (void)fetchVerifyCode:(NSString *)mobile
                success:(void(^)(NSString *status))success
                failure:(void(^)(NSError *error))failure;{
    
    NSString *url = [NSString stringWithFormat:@"%@/index.php?s=/app/user/sendcode.html",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"phone"] = mobile;
    
    [[BVHttpManager sharedNetManager]requstUrl:url method:Post parameters:params success:^(id responseObject) {
        BVLog(@"----服务器返回的----%@",responseObject);
        NSString *str= [NSString stringWithFormat:@"%@",responseObject[@"code"]];
        if (([str isEqualToString:CODE] && responseObject!=nil)) {
            success(responseObject[@"message"]);
        }else{
            NSError *error;
            failure(error);
        }

    } failure:^(NSError *error) {
        failure(error);
    }];

}

+ (void)registeredSex:(NSString *)sex
            dateBirth:(NSString *)dateBirth
              address:(NSString *)address
        maritalStatus:(NSString *)maritalStatus
               mobile:(NSString *)mobile
                 code:(NSString *)code
                  pwd:(NSString *)pwd
              success:(void(^)(NSString *status))success
          codeFailure:(void(^)(NSString *str))codeFailure
              failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/index.php?s=/app/user/registerdo.html",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"sex"] = sex;
    params[@"birthday"] = dateBirth;
    params[@"region"] = address;
    params[@"marry"] = maritalStatus;
    
    params[@"mobile"] = mobile;
    params[@"code"] = mobile;
    params[@"password"] = pwd;
    params[@"rpassword"] = pwd;
    
    [[BVHttpManager sharedNetManager]requstUrl:url method:Post parameters:params success:^(id responseObject) {
        BVLog(@"----服务器返回的----%@",responseObject[@"message"]);
        NSString *str= [NSString stringWithFormat:@"%@",responseObject[@"status"]];
        if (([str isEqualToString:CODE] && responseObject!=nil)) {
            success(responseObject[@"message"]);
        }else{
            codeFailure(responseObject[@"message"]);
        }
        
    } failure:^(NSError *error) {
        failure(error);
    }];
}

- (void)opinionFeedback:(NSString *)opinion
                success:(void(^)(NSString *status))success
                failure:(void(^)(NSError *error))failure{
    
}

- (void)setNickName:(NSString *)nickName
                sex:(NSString *)sex
             height:(NSString *)height
          education:(NSString *)education
       professional:(NSString *)professional
      monthlysalary:(NSString *)monthlysalary
            address:(NSString *)address
          dateBirth:(NSString *)dateBirth
            success:(void(^)(NSString *status))success
            failure:(void(^)(NSError *error))failure{
    
    
}

- (void)setSpouseConditionsSuccess:(void(^)(NSString *status))success
                       codeFailure:(void(^)(NSString *str))codeFailure
                           failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/index.php?s=/app/user/savemate.html",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    BVMineModel *model = [BVMineModel shareTools];
    
    params[@"uid"] = @"20170400";
    
    params[@"age"] = @"18";
    params[@"height"] = model.spouse_height;
    params[@"eduction"] = model.spouse_education;
    params[@"region"] = model.spouse_address;
    params[@"faith"] = model.spouse_faith;
    params[@"marry"] = model.spouse_maritalStatus;
    params[@"house"] = model.spouse_housePurchase;
    params[@"car"] = model.spouse_carPurchase;
    params[@"icome"] = model.spouse_monthlySalary;
    params[@"live"] = model.spouse_liveParents;
    params[@"is_child"] = model.spouse_wantChild;
    
    NSLog(@"--------%@",params[@"faith"]);
    [[BVHttpManager sharedNetManager]requstUrl:url method:Post parameters:params success:^(id responseObject) {
        BVLog(@"----服务器返回的----%@",responseObject[@"message"]);
        NSString *str= [NSString stringWithFormat:@"%@",responseObject[@"status"]];
        if (([str isEqualToString:CODE] && responseObject!=nil)) {
            success(responseObject[@"message"]);
        }else{
            codeFailure(responseObject[@"message"]);
        }
        
    } failure:^(NSError *error) {
        failure(error);
    }];
}

- (void)fetchSpouseConditionsSuccess:(void(^)(NSString *status))success
                         codeFailure:(void(^)(NSString *str))codeFailure
                             failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/index.php?s=/app/user/getmate.html",PATH];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"uid"] = @"20170400";

    BVMineModel *model = [BVMineModel shareTools];
    [[BVHttpManager sharedNetManager]requstUrl:url method:Post parameters:params success:^(id responseObject) {
        BVLog(@"----服务器返回的----%@",responseObject[@"message"]);
        NSString *str= [NSString stringWithFormat:@"%@",responseObject[@"status"]];
        if (([str isEqualToString:CODE] && responseObject!=nil)) {
            NSDictionary *dic = responseObject[@"list"];
            model.spouse_age = dic[@"age"];
            model.spouse_height = dic[@"height"];
            model.spouse_education = dic[@"eduction"];
            model.spouse_address = dic[@"city"];
            model.spouse_faith = dic[@"faith"];
            model.spouse_maritalStatus = dic[@"marry"];
            model.spouse_housePurchase = dic[@"house"];
            model.spouse_carPurchase = dic[@"car"];
            model.spouse_monthlySalary = dic[@"icome"];
            model.spouse_liveParents = dic[@"live"];
            model.spouse_wantChild = dic[@"is_child"];
            success(responseObject[@"message"]);
        }else{
            codeFailure(responseObject[@"message"]);
        }
        
    } failure:^(NSError *error) {
        failure(error);
    }];
    
}
@end
